package A3GCConcreteTestCase;


public class Launcher 
{
	private static final String location1    = "Location1";
	private static final String location2    = "Location2";
	private static final String specialGroup = "Special";
	private static final String xGroup       = "XGroup";
	public static void main( String[] args )
	{
		try
		{
			ConcreteNode node1 = new ConcreteNode("The First Node" );
			node1.addSupervisorRole(location1, new LocationSupervisorRole(0, location1) );
			node1.addFollowerRole( specialGroup, new ConcreteFollower(1, specialGroup ) );
			//node1.addSupervisorRole( specialGroup, new ConcreteSupervisor(1, specialGroup ) );
			
			node1.joinGroup(specialGroup);
			node1.joinGroup(location1);
			
			Thread.sleep(1000);
			
			ConcreteNode node2 = new ConcreteNode("The Second Node" );
			node2.addSupervisorRole( location1, new LocationSupervisorRole(0, location1 ) );
			node2.addFollowerRole( specialGroup, new ConcreteFollower(2, specialGroup ) );
			
			node2.joinGroup(specialGroup);
			node2.joinGroup(location1);

			Thread.sleep(1000);
			
			ConcreteNode node3 = new ConcreteNode("The Third Node");
			node3.addSupervisorRole( location1, new LocationSupervisorRole(0, location1 ) );
			node3.addFollowerRole( specialGroup, new ConcreteFollower(3, specialGroup) );
			node3.addSupervisorRole( specialGroup, new ConcreteSupervisor(0, specialGroup) );

			
			node3.joinGroup(specialGroup);
			node3.joinGroup(location1);
			
			Thread.sleep(5000);
			
			ConcreteNode nodeX1 = new ConcreteNode("The X1 Node");
			nodeX1.addSupervisorRole( location2, new LocationSupervisorRole(0, location2 ) );
			nodeX1.addFollowerRole(xGroup, new ConcreteFollower( 1, xGroup ) );
			nodeX1.addSupervisorRole(xGroup, new ConcreteSupervisor(1, xGroup) );
			nodeX1.addFollowerRole( specialGroup, new ConcreteFollower(1, specialGroup) );
			
			nodeX1.joinGroup(xGroup);
			nodeX1.joinGroup(location2);
			
			Thread.sleep(1000);
			
			ConcreteNode nodeX2 = new ConcreteNode("The X2 Node");
			nodeX2.addSupervisorRole( location2, new LocationSupervisorRole(0, location2 ) );
			nodeX2.addFollowerRole(xGroup, new ConcreteFollower( 2, xGroup) );
			nodeX2.addFollowerRole(specialGroup, new ConcreteFollower( 2, specialGroup ) );
			
			nodeX2.joinGroup(xGroup);
			nodeX2.joinGroup(location2);
			
			ConcreteNode nodeX3 = new ConcreteNode("The X3 Node");
			nodeX3.addSupervisorRole( location2, new LocationSupervisorRole(0, location2 ) );
			nodeX3.addFollowerRole(xGroup, new ConcreteFollower( 3, xGroup) );
			nodeX3.addFollowerRole(specialGroup, new ConcreteFollower( 3, specialGroup ) );
			
			nodeX3.joinGroup(location2);
			//nodeX3.joinGroup(xGroup);
			//nodeX3.joinGroup(specialGroup);
			
			Thread.sleep(10000);
			
			ConcreteNode clientNode = new ConcreteNode("Location 1 Client Node");
			clientNode.addFollowerRole(location1, new ClientNode(0, location1) ); 
			
			clientNode.joinGroup(location1);
			
			System.exit(0);
			Thread.sleep(120000);
			
			clientNode.terminate(location1);
			
			node2.terminate(specialGroup);
			node2.terminate(location1);
			node3.terminate(specialGroup);
			node3.terminate(location1);
			
			
			Thread.sleep(10000);
			
			node1.terminate(specialGroup);
			node1.terminate(location1);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		
		System.exit(0);
	}
}
